package GraphProperties;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;

import Definitions.NodeClass;

public class ShortestPathRelatedPropsClass extends GenericGraphPropertyClass implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6889154053751502702L;
	double[][] shortestPaths;
	double numberOfPaths;
	double cumulativeLengthOfThePaths;
	double averagePathLength;
	double diameter=0;
	Map<Double, Integer> shortestPathDistibutionMap;
	
	double betweennessCentralities[];
	
	
	ShortestPathRelatedPropsClass()
	{
		super(null);
	}
	
	public void setPropertiesIBelongTo(PropertiesOfGraphClass propertiesIBelongTo)
	{
		this.propertiesIBelongTo = propertiesIBelongTo;
	}
	
	
	ShortestPathRelatedPropsClass(PropertiesOfGraphClass propertiesIBelongTo)
	{
		super(propertiesIBelongTo);
		numberOfPaths = 0;
		cumulativeLengthOfThePaths = 0;
		averagePathLength = 0;
		this.propertiesIBelongTo = propertiesIBelongTo;
		
	}		
			
	public double getShortestPathBetweenNodes(NodeClass x , NodeClass y)
	{
		return shortestPaths[x.getOrder()][y.getOrder()];			
	}
	
	public void setShortestPathResultParameters(double[][] shortestPaths, double[] betweennessCentralities, double cumulativeLengthOfThePaths, double numberOfPaths, Map<Double, Integer> shortestPathDistibutionMap, double diameter)
	{
		this.shortestPaths = shortestPaths;
		this.cumulativeLengthOfThePaths=cumulativeLengthOfThePaths;
		this.numberOfPaths=numberOfPaths;
		averagePathLength = cumulativeLengthOfThePaths/numberOfPaths;
		this.shortestPathDistibutionMap= shortestPathDistibutionMap;
		this.diameter = diameter;		
		
		this.betweennessCentralities = betweennessCentralities;		
	}
	
	public double getNumberOfPaths()
	{
		return numberOfPaths;			
	}		
	
	public double[] getBetweennessCentralities()
	{
		return betweennessCentralities;			
	}
	
	
	
	public double getCumulativeLengthOfThePaths()
	{
		return cumulativeLengthOfThePaths;			
	}
	
	public double getAveragePathLength()
	{
		return averagePathLength;			
	}
	
	public double getDiameter()
	{
		return diameter;			
	}		
	
	
	public ArrayList<NodeClass> getNeighboursOfTheNode(NodeClass node, int degreeLevel, boolean isExact)
	{
		ArrayList<NodeClass> neighboursOfTheNodeWrtGivenCriteria;
		
		neighboursOfTheNodeWrtGivenCriteria =new ArrayList<NodeClass>();
		
		int orderOfTheNode = node.getOrder();
		
		ArrayList<NodeClass> datasetOfTheGraph = propertiesIBelongTo.myGraph.getDataSet();
		
		if(isExact)
		{				
			for(int i=0; i<shortestPaths[0].length; i++)
			{
				if(shortestPaths[orderOfTheNode][i]==degreeLevel)
					neighboursOfTheNodeWrtGivenCriteria.add(datasetOfTheGraph.get(i));
					
			}
		}
		else
		{
			for(int i=0; i<shortestPaths[0].length; i++)
			{
				if(shortestPaths[orderOfTheNode][i]<=degreeLevel)
					neighboursOfTheNodeWrtGivenCriteria.add(datasetOfTheGraph.get(i));
					
			}				
			
		}
		return neighboursOfTheNodeWrtGivenCriteria;
	}
}